﻿/*
 * QWine Queue Machine (Special build for Immigration Office)
 * Copyright (C) 2010 Wish Enterprise Development Team

 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 * Contact Us:
 * E-Mail   : contact@wishenterprise.com
 * 
 * */

using System;
using System.Drawing;
using System.Net;
using System.Windows.Forms;
using QWEntity;

namespace QWRepository
{
    /// <summary>
    /// EnvironmentRepository
    /// </summary>
    public static class EnvironmentRepository
    {
        /// <summary>
        /// Pasangs the warna alternatif.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public static void PasangWarnaAlternatif(ListView obj)
        {
            int i = 0;
            foreach (ListViewItem r in obj.Items)
            {
                i++;
                r.BackColor = (i % 2).Equals(0) ? Color.Cornsilk : Color.White;
            }
        }

        /// <summary>
        /// Lists the view sorting at column click.
        /// </summary>
        /// <param name="listViewColumnSorter">The list view column sorter.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.ColumnClickEventArgs"/> instance containing the event data.</param>
        public static void ListViewSortingAtColumnClick(
                ListViewColumnSorter listViewColumnSorter, ColumnClickEventArgs e)
        {
            if (e.Column ==
                listViewColumnSorter.SortColumn)
            {
                listViewColumnSorter.Order = listViewColumnSorter.Order == SortOrder.Ascending
                                                     ? SortOrder.Descending
                                                     : SortOrder.Ascending;
            }
            else
            {
                listViewColumnSorter.SortColumn = e.Column;
                listViewColumnSorter.Order = SortOrder.Ascending;
            }
        }

        /// <summary>
        /// Gets the local session.
        /// </summary>
        /// <returns></returns>
        public static string GetLocalSession()
        {
            // Get ServerDate
            var si = new ServerInfoRepository().GetServerInfo();
            return GetLocalIpAddress() + si.Now.ToString("yyyyMMddHHmmss");
        }

        /// <summary>
        /// Gets the local ip address.
        /// </summary>
        /// <returns></returns>
        public static string GetLocalIpAddress()
        {
            return Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
        }

        /// <summary>
        /// Gets the server date time.
        /// </summary>
        /// <returns></returns>
        public static DateTime GetServerDateTime()
        {
            var si = new ServerInfoRepository().GetServerInfo();
            return si.Now;
        }

        /// <summary>
        /// Suppresses the char.
        /// </summary>
        /// <param name="letter">The letter.</param>
        /// <returns></returns>
        public static string SuppressChar(string letter)
        {
            string tmp = letter.Replace("'", "");
            return tmp;
        }
    }
}
